/*    
    OpenMheg - A free MHEG-5 library
    Copyright (C) 2008 Dharmesh Malam

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Reflection;
using Core.Model.Ingredients.Presentable.Visibles;
using Rectangle=System.Drawing.Rectangle;

namespace WinForms.Renderer.GDI.Drawers
{
    public class BitmapDrawer : Drawer
    {
        public override Type GetVisible
        {
            get
            {
                //Assembly assembly = Assembly.Load( "OpenMHEG.Core" );
                //return assembly.GetType( "Core.Model.Bitmap" , true);

                return typeof (Core.Model.Ingredients.Presentable.Visibles.Bitmap);
            }
        }

        public override void Draw ( Visible v , Graphics g )
        {
            //scale I-frames, not png
            //apply trans to m2v, not png kinda, 1.06 - 4.4.1
            //png = contenthook 4, m2v = contenthook 2

            var bitmap = ( Core.Model.Ingredients.Presentable.Visibles.Bitmap ) v;
            
            Image image = bitmap.Content.BitmapContent;
            
            if ( image !=null )
            {

                if ( bitmap.ContentHook == 4 || !bitmap.Scale.HasValue)
                {
                    g.DrawImageUnscaledAndClipped(image, new Rectangle(bitmap.BoxPosition.X + bitmap.DecodeOffset.X,
                                            bitmap.BoxPosition.Y + bitmap.DecodeOffset.Y, image.Width, image.Height) );
                }
                else
                {
                    g.DrawImage( image, bitmap.BoxPosition.X + bitmap.DecodeOffset.X,
                                            bitmap.BoxPosition.Y + bitmap.DecodeOffset.Y,
                                            bitmap.Scale.Value.Width, bitmap.Scale.Value.Height );
                }
            }
      
        }
    }
}
